import type { ResponseOption } from "../../res/ResponseOption.js";
import { fields, ResOp } from "./utils.js";

export const variableChange: ResponseOption = {
    name: "0x00 03 图元属性改变",
    description: "图元属性改变",
    fields: [
        fields.op(ResOp.VarChange),
        fields.crc,
        fields.length,
        {
            name: "画面 ID",
            kind: "u16",
        },
        {
            name: "变量改变",
            kind: "custom",
            desc: "循环：每个变量由组件ID(u16)、属性ID(u8)、索引(u8)、类型(u8)、值(u16)组成",
            matcher(data) {
                let str = "";
                while (data.length > 0) {
                    const component_id = data.u16le();
                    data.consume(2);
                    const attribute_id = data.u8();
                    data.consume(1);
                    const index = data.u8();
                    data.consume(1);
                    const type = data.u8();
                    data.consume(1);
                    const value = data.u16le();
                    data.consume(2);
                    str += `\nid: ${component_id}-${attribute_id}-${index}, kind: ${type}, value: ${value}`;
                }
                return str;
            },
        },
    ],
};
